<extend name="./Application/Common/View/block/base.php" />
<block name="header">
    <include file="./Application/Admin/View/block/easyui_header.php" />
    <include file="./Application/Admin/View/block/amap_header.php" />
    <link href="__PUBLIC__/css/Content/index.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" type="text/css" href="/Public/uploadfy/uploadify.css" />
    <script type="text/javascript" src="/Public/uploadfy/jquery.uploadify.min.js"></script>
    <style>
        #dg{
            height: 100%;;
        }
        #tabs_pumpstation table{
            line-height: 30px;;
        }
    </style>
    <script>
        function switchPumpStation(id) {
            $('#rivergate_id').val(id);
            $('.ps_id_hidden').val(id);
            //清空所有form
            $('form').form('clear');
            $("input[name='pumpid']").val(id);
            $('#grid_weather_log').datagrid({queryParams:{'facilities_type':3,'facilities_id':$('#rivergate_id').val(),page:1,rows:20}});
            editRivergate($('#rivergate_id').val());
        }

    </script>
</block>
<block name="bdoy">
    <body>
    <table id="dg"></table>
    <div id="toolbar" style="padding:5px;height:auto">
        <div style="margin-bottom:5px">
            <?php if(!I('get.justsee')){?>
            <a href="#" id="add_button" class="easyui-linkbutton" iconCls="icon-add" plain="true">新增</a>
            <a href="#" id="edit_button" class="easyui-linkbutton" iconCls="icon-edit" plain="true">编辑</a>
            <a href="#" id="del_button" class="easyui-linkbutton" iconCls="icon-remove" plain="true">删除</a>
            <?php }?>
            <a href="#" id="search_button" class="easyui-linkbutton" iconCls="icon-search" plain="true">高级搜索</a>
            <?php if(!I('get.justsee')){?>
            <a href="#" id="reload_button" class="easyui-linkbutton" iconCls="icon-reload" plain="true">重载</a>
                <a href="#" class="easyui-linkbutton" iconCls="icon_ext icon-import" plain="true" onclick="open_dialog('/Manage/Admin/open_window_import?url=__URL__/import')">导入</a>
                <a href="#" class="easyui-linkbutton" iconCls="icon_ext icon-rescueLog" plain="true" onclick="open_tab('__URL__/export')">导出</a>
            <?php }?>
            <?php if(I('get.justsee')){?>
                <a href="#" id="edit_button" class="easyui-linkbutton" iconCls="icon-edit" plain="true">查看</a>
            <?php }?>
            <!--            <a href="#" id="clear_button" class="easyui-linkbutton" iconCls="icon-redo" plain="true">{:LANG('clearSelections')}</a>-->
        </div>
        <form id="query_form_base_info" method="post" action="">
            <table>
                    <td>河道闸门名称</td>
                    <td>
                        <input id="pump_station" name="gate_name"/>
                    </td>

                    <td><a id="query_button_base_info" href="#" class="easyui-linkbutton" iconCls="icon-search">查询</a></td>
                    <td><a href="#" class="easyui-linkbutton" iconCls="icon-undo" onclick="javascript:$('#query_form_base_info').form('clear');">重置</a></td>
                </tr>
            </table>
        </form>
        <div id="queryMaterialsRemovalParamZone">
            <fieldset>
                <legend>属性搜索</legend>
                <form id="query_form" method="post" action="">
                    <table>
                        <tr>
                            <td>属性</td>
                            <td id="table_field">
                                <input class="easyui-combobox"/>
                            </td>
                            <td>查询条件</td>
                            <td id="condition_td">
                                <input type="text"/>
                            </td>

                            <td><a id="query_button" href="#" class="easyui-linkbutton" iconCls="icon-search">查询</a></td>
                            <td><a href="#" class="easyui-linkbutton" iconCls="icon-undo" onclick="javascript:$('#query_form').form('clear');">重置</a></td>
                        </tr>
                    </table>
                </form>
            </fieldset>
            <fieldset>
                <legend>高级搜索</legend>
                <form id="query_form_gen" method="post" action="">
                    <table>
                        <tr>
                            <td>运行情况</td>
                            <td>
                                <select name="status" data-options="prompt:'{:LANG('pls_input')}',required:true" style="width: 80px;">
                                    {:station_status_option()}
                                </select>
                            </td>
                            <td><a id="query_button_gen" href="#" class="easyui-linkbutton" iconCls="icon-search">查询</a></td>
                            <td><a href="#" class="easyui-linkbutton" iconCls="icon-undo" onclick="javascript:$('#query_form_gen').form('clear');">重置</a></td>
                        </tr>
                    </table>

                </form>
            </fieldset>
        </div>
    </div>
    <div id="listDialog" class="easyui-dialog" title="河闸信息" closed="true" fit="true" resizable='false' modal="true" minimizable="false" collapsible="false">
        <input type="hidden" id="rivergate_id" name="rivergate_id"/>
        <div class="easyui-tabs" id="tabCtrl" fit="true" border="false">
            <div title="河道闸门基础信息" id="subTabCtrl_1" fit=true  closable="false" style="padding:10px;" href="__URL__/base_info?justsee={:I('get.justsee')}" loadingMessage="{:LANG('loading')}">

            </div>
            <?php if(!I('get.justsee')){?>
            <div title="雨情记录" closable="false"  style="padding:10px;" href="__URL__/weather_log" loadingMessage="{:LANG('loading')}" fit="true">

            </div>
            <?php }?>
        </div>
    </div>
    </body>
</block>
<block name="footExtendJs">
    <script type="text/javascript">
        $(function(){
            $('#pump_station').combobox({
                url:'/Manage/AdminGate/get_all_combox',
                valueField:'name',
                textField:'name',
                width:180,
            });
            var request_url = '__URL__/get_all';
            var add_title = '新增';
            var edit_title = '编辑';
            jQuery('#dg').datagrid({
                fit: true,
                nowrap: false,
                striped: true,
                collapsible: false,
                showFooter: true,
                url: request_url,
                method: 'get',
                pageNumber: 1,
                pageSize: 20,
                pageList: [20, 50, 100, 200],
                idField: 'id',
                remoteSort: true,
                sortOrder: 'desc',
                columns: [[
                    {field: 'ck', title: '', width: 80, checkbox: true, align: 'center'},
                    {field: 'id', title: 'ID', width: 80, align: 'center',hidden:true},
                    {field: 'gate_name', title: '闸门名称', width: 120, align: 'center'},
                    {field:'charge_person',title:'执勤人员', width:180,align:'center',sortable:true},
                    {field:'status',title:'运行情况', width:80,align:'center',sortable:true},
                    {field: 'gate_ctltype', title: '闸门控制类型', width: 120, align: 'center'},
                    {field: 'gate_switsty', title: '闸门启闭型式', width: 120, align: 'center'},
                ]],
                pagination: true,
                rownumbers: true,
                singleSelect: false,
                toolbar: '#toolbar',
                onDblClickRow: function (rowIndex, rowData) {
                    switchPumpStation(rowData.id);
                    $('#listDialog').dialog({title:rowData.gate_name,modal: true});
                    $('#listDialog').dialog('open');
                    $('#listDialog').dialog('maximize');
                    $('#tabs_gate').tabs({
                        height: $('#subTabCtrl_1').height(),
                        width: $('#subTabCtrl_1').width() - 20
                    });
                },
            });
        });
        //按钮事件绑定
        $('#add_button').click(function(){
            addRivergate();
            $('#rivergate_id').val('');
            $('#listDialog').dialog({modal:true});
            $('#listDialog').dialog('open');
            $('#listDialog').dialog('maximize');
            $('#tabs_gate').tabs({height:$('#subTabCtrl_1').height(),width:$('#subTabCtrl_1').width()-20});

        });
        $('#edit_button').click(function(){
            var rows = $('#dg').datagrid('getSelections');
            if(rows.length > 1){
                $.messager.alert('提示','当前选择了多条信息，不可以编辑！','error');
                return;
            }
            var obj = jQuery('#dg').datagrid('getSelected');
            if(!obj){
                msgShow('{:LANG('tips')}', '{:LANG('pls_slet_row')}', 'warning');
            }
            switchPumpStation(obj.id);
            $('#listDialog').dialog({title:obj.gate_name,modal:true});
            $('#listDialog').dialog('open');
            $('#listDialog').dialog('maximize');
            $('#tabs_gate').tabs({height:$('#subTabCtrl_1').height(),width:$('#subTabCtrl_1').width()-20});

        });
        $('#del_button').click(function(){
            var ids = [];
            var rows = $('#dg').datagrid('getSelections');
            for ( var i = 0; i < rows.length; i++) {
                ids.push(rows[i].id);
            }
            jQuery.messager.confirm('请确认', '你确定要删除吗？', function(r){
                if (r){
                    $.ajax({
                        url:"__URL__/deleteArray",
                        data:{"ids":ids.join(',')},
                        method: "post",
                        dataType: "json",
                        async: true,
                        success: function(data) {
                            if (data.status==1) {
                                $('#rivergate_id').val('');
                                $('#dg').datagrid('reload');
                                $('#dg').datagrid("unselectAll");
                                $.messager.show({title:'提示',msg:'删除成功！',showType:'slide'});
                            }
                            else $.messager.alert('提示','删除失败！','error');
                        },
                        error: function(XMLHttpRequest, textStatus, errorThrown) {
                            $.messager.alert('提示','删除出错，错误类型为!'+textStatus,'error');
                        }
                    });
                }
            });
        });
        $('#search_button').click(function(){
            $('#queryMaterialsRemovalParamZone').toggle();
            $('#dg').datagrid("resize");
        });
        $('#reload_button').click(function(){
            $('#dg').datagrid('load', {});
        });
        $('#reload_clear').click(function(){
            $('#dg').datagrid('clearSelections');
        });

        $('#query_button').click(function(){
            var obj = $('#query_form').serializeJson();
            $('#dg').datagrid('load',obj);
        });
        $('#query_button_gen').click(function() {
            var obj = $('#query_form_gen').serializeJson();
            obj['gen'] = '1';
            $('#dg').datagrid('load',obj);
        });
        $('#query_button_base_info').click(function(){
            var obj = $('#query_form_base_info').serializeJson();
            $('#dg').datagrid('load',obj);
        });
        var model = 'Gate';
        table_index_change(model, 'base');
        $('#queryMaterialsRemovalParamZone').hide();

    </script>
</block>
